<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Promise</title>
</head>

<body>
    <!-- 为什么会有Promise？因为 在此之前一直是回调函数来做主流，只能嵌套函数 -->
    <script>
        let pro = new Promise((resolve, reject) => {
            let random = Math.random() * 100;
            if (random > 5) {
                resolve({
                    color: 'red',
                    price: '¥99'
                })
            } else {
                reject(new Error('加班去了，忙去了'));
            }
        });

        pro.then((onfufilled) => {
            console.log('成功', onfufilled);
        }, (onreject) => {
            console.log('失败', onreject);
        }).catch((err) => {
            console.log('err', err);
        })
    </script>
</body>

</html>